package com.mianshi;

public class wuba2 {
    static int ans = 0;
    public static void main(String[] args) {
//        calculateExtraNum(30,3);
//        System.out.println(ans);
//        dfs(40,4);
//        System.out.println(ans);
        int ans = calculateExtraNum(30,3);
        System.out.println(ans);
    }

//    public static int calculateExtraNum (int totalNum, int exchangeNum) {
//        // write code here
//        if(totalNum < exchangeNum){
//            return 0;
//        }
//        int temp = totalNum / exchangeNum;
//        ans += temp;
//        return ans + calculateExtraNum(temp,exchangeNum);
//    }
//
//    public int calculateExtraNum (int totalNum, int exchangeNum) {
//        // write code here
//        dfs(totalNum,exchangeNum);
//        return ans;
//    }

    public static void dfs(int totalNum, int exchangeNum){
        if(totalNum < exchangeNum){
            return;
        }
        totalNum = totalNum / exchangeNum;
        ans += totalNum;
        dfs(totalNum,exchangeNum);
    }


    public static int calculateExtraNum (int totalNum, int exchangeNum) {
        // write code here
        int ans = 0;
        while(totalNum >= exchangeNum){
             totalNum /= exchangeNum;
            ans += totalNum;
        }
        return ans;
    }
}
